<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('监督日志列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <p>日志编号：</p>
                                <input type="text" name="code"/>
                            </li>
                            <li class="select-time">
                                <p>日志日期：</p>
                                <input type="text" class="time-input" placeholder="开始时间" name="beginWorkDate" required/>
                                <span>-</span>
                                <input type="text" class="time-input" placeholder="结束时间" name="endWorkDate"/>
                            </li>
                            <li>
                                <p>所属机构号：</p>
                                <input name="brCode" onclick="selectDeptTree()"  id="treeId" type="text" placeholder="请选择" class="form-control">
                            </li>
                            <li>
                                <p>监督员：</p>
                                <input type="text" name="createOper"/>
                            </li>
                            <li class="select-time">
                                <p>创建时间：</p>
                                <input type="text" class="time-input"  placeholder="开始时间" name="beginCreateDate"/>
                                <span>-</span>
                                <input type="text" class="time-input" placeholder="结束时间" name="endCreateDate"/>
                            </li>
                            <li>
                                <p>状态：</p>
                                <select name="auditStatus" th:with="type=${@dict.getType('wt_check_daylog_auditstatus')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="_downLoad()" shiro:hasPermission="wt:auditDaylogQuery:export">
                    <i class="fa fa-download"></i> 下载日志
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="wt:auditDaylogQuery:export">
                    <i class="fa fa-download"></i> 导出
                 </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('wt:auditDaylogQuery:edit')}]];
        var removeFlag = [[${@permission.hasPermi('wt:auditDaylogQuery:remove')}]];
        var prefix = ctx + "wt/auditDaylogQuery";
        var auditingStatus = [[${@dict.getType('wt_check_daylog_auditstatus')}]];
        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                showExport:true,
                modalName: "监督日志",
                //启用跳转至指定页
                showPageGo: true,
                //启用点击选中行
                clickToSelect: true,
                columns: [{
                    radio: true
                },
                {
                    field : 'id', 
                    title : 'ID',
                    visible: false
                },
                {
                    field : 'code', 
                    title : '日志编号'
                },
                {
                    field : 'workDate', 
                    title : '日志日期'
                },
                {
                    field : 'brCode', 
                    title : '所属机构号'
                },
                {
                    field : 'createOper', 
                    title : '监督员'
                },
                {
                    field : 'createDate', 
                    title : '创建时间'
                },
                {
                    field : 'auditStatus',
                    title : '状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(auditingStatus, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="viewDetail(\'' + row.id + '\')"><i class="fa fa-edit"></i>详情</a> ');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        //选择机构
        function selectDeptTree() {
            var treeId = $("#treeId").val();
            var deptId = $.common.isEmpty(treeId) ? "00038" : $("#treeId").val();
            var url = ctx + "system/dept/selectDeptTree/" + deptId;
            var options = {
                title: '选择部门',
                width: "380",
                url: url,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }
        function doSubmit(index, layero){
            var tree = layero.find("iframe")[0].contentWindow.$._tree;
            if ($.tree.notAllowParents(tree)) {
                var body = layer.getChildFrame('body', index);
                $("#treeId").val(body.find('#treeId').val());
                layer.close(index);
            }
        }
        function viewDetail(id){
            //$.modal.open(title, url, width, height, callback)
            table.set();
            if($.common.isEmpty(id) && table.options.type == table_type.bootstrapTreeTable) {
                var row = $("#" + table.options.id).bootstrapTreeTable('getSelections')[0];
                if ($.common.isEmpty(row)) {
                    $.modal.alertWarning("请至少选择一条记录");
                    return;
                }
                var url = table.options.updateUrl.replace("{id}", row[table.options.uniqueId]);
                //$.modal.openFull("查看监控日志",url,850,650);
                var returnValue = window.showModalDialog(url,window,"dialogWidth=850px; dialogHeight=650px; help=no; status=no; scroll=yes; resizable=no;");
                if(returnValue){
                    $.table.refresh();
                }
            } else {
                //$.modal.openFull("查看监控日志",$.operate.editUrl(id),850,650);
                var returnValue = window.showModalDialog($.operate.editUrl(id),window,"dialogWidth=850px; dialogHeight=650px; help=no; status=no; scroll=yes; resizable=no;");
                if(returnValue){
                    $.table.refresh();
                }
            }

        }
//原js
        function _downLoad(){

            var ids = $.table.selectColumns("id");
            if (ids.length>1) {
                $.modal.alertWarning("请选择一条记录");
                return;
            }else if(ids.length<1){
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            var row = $("#" + table.options.id).bootstrapTable('getSelections')[0];
            if(row.state!=1){
                alert('未提交，不能导出');
                return false;
            }
            $.operate.post(prefix + "/downLoad",row,function (result) {
                //alert(result.msg);
                if (result.code == web_status.SUCCESS) {
                    window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
                } else if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                } else {
                    $.modal.alertError(result.msg);
                }
                $.modal.closeLoading();
            });
        }
    </script>
</body>
</html>